package cn.cloudtogo.server.atomapi;

import cn.cloudtogo.common.atomapi.token.ApiResource;
import cn.cloudtogo.common.atomapi.token.Expiration;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yaolianhua789@gmail.com
 **/
@Data
public class ApiTokenCreateParam {

    private String uuid;
    @JsonProperty("name")
    private String notes;

    private boolean disable;

    private Expiration expiration;

    private List<ApiResource> resources = new ArrayList<>();

    public static ApiTokenCreateParam ofGlobal(String uuid, String notes) {
        return ofGlobal(uuid, notes, true);
    }

    public static ApiTokenCreateParam ofGlobal(String uuid, String notes, boolean disable) {
        ApiTokenCreateParam param = new ApiTokenCreateParam();

        List<ApiResource> global = List.of(ApiResource.of("GET", String.format("/api/%s/*", uuid)),
                ApiResource.of("POST", String.format("/api/%s/*", uuid)),
                ApiResource.of("DELETE", String.format("/api/%s/*", uuid)),
                ApiResource.of("PUT", String.format("/api/%s/*", uuid)));

        param.setUuid(uuid);
        param.setNotes(notes);
        param.setResources(global);
        param.setDisable(disable);

        return param;
    }

}
